package com.kj.report.service.impl;

import org.springframework.stereotype.Service;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

@Service
public class HealthAdviceServiceImpl {
    public String scriptEngine(Integer sex, Integer lvl, String expression,
                               String format) {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        engine.put("sex", sex);
        engine.put("lvl", lvl);
        try {
            engine.eval(expression);
        } catch (ScriptException e) {
            e.printStackTrace();
        }
        return format.replaceAll("X", engine.get("x")+"").replaceAll("Y", engine.get("y")+"");
    }


}
